//-----------------------------------------------------------------------------
// File: CommonDefinitions.cs
//
// Copyright (c) Dmitry Shuklin. All rights reserved.
//-----------------------------------------------------------------------------
using System;


namespace ObjectiveDraw.Platform
{
	public class CoordinatePosition
	{
		public float Value;
		public double Scale;
		public float Offset;
		public float Margin;
		public float Aperture;
	}

	public class DrawerChartContext
	{
		public CoordinatePosition AbscissaPosition = null;
		public CoordinatePosition OrdinatePosition = null;
	}


	public interface IDrawerShape : Cerebrum.IReleasable, IDrawerComponent 
	{
		bool UpdateShape(ObjectiveDraw.Platform.DrawerChartBase control, ChartInfoArgs cinfo, Cerebrum.Direct3D.Forms.DeviceEventArgs de, bool idle, out UpdateShapeInfo uinfo);
		void RenderShape(ObjectiveDraw.Platform.DrawerChartBase control, ChartInfoArgs cinfo, Cerebrum.Direct3D.Forms.RenderEventArgs re, float z);
		void OnMouseDown(ObjectiveDraw.Platform.DrawerChartBase control, System.Windows.Forms.MouseEventArgs e);
		void OnMouseMove(ObjectiveDraw.Platform.DrawerChartBase control, System.Windows.Forms.MouseEventArgs e);
		void OnMouseUp(ObjectiveDraw.Platform.DrawerChartBase control, System.Windows.Forms.MouseEventArgs e, ref bool CaptureMaouse);
		void OnKeyPress(ObjectiveDraw.Platform.DrawerChartBase control, System.Windows.Forms.KeyPressEventArgs e);
		void OnKeyDown(ObjectiveDraw.Platform.DrawerChartBase control, System.Windows.Forms.KeyEventArgs e);
		float DistanceFrom(ObjectiveDraw.Platform.DrawerChartBase control, System.Drawing.PointF point);
		bool Selected {get; set;}
		bool IsDataSource {get; }
		bool GetAbscissaExtents(ref float min, ref float max);
		bool GetOrdinateExtents(ref float min, ref float max);
	}

	public interface IDrawerComponent : Cerebrum.Desktop.Configuration.IConfigurable //--: Cerebrum.Integrator.ISerializable
	{
		Cerebrum.Integrator.DomainContext DomainContext {get;}
		Cerebrum.ObjectHandle ObjectHandle {get; set;}
		string TypeName {get; set;}
		void Serialize(ObjectiveDraw.Platform.Serialization.FallbackChain storage, SerializationContext context);
		IDrawerComponent OwnerComponent{get;}
		/*--Workspace Workspace{get;}
		System.Collections.Hashtable Variables {get;}--*/
	}

	public sealed class KnownDrawerComponents
	{
		private KnownDrawerComponents() {}

		public const string DrawerConfigurator				= "ObjectiveDraw.Configurator";

		public const string IntegerConfigurator		=	"Desktop.Configuration.ConfigIntegerEditor";
		public const string BooleanConfigurator		=	"Desktop.Configuration.ConfigBooleanEditor";
		public const string StringConfigurator		=	"Desktop.Configuration.ConfigStringEditor";
		public const string ImageConfigurator		=	"Desktop.Configuration.ConfigImageEditor";
		public const string ColorConfigurator		=	"Desktop.Configuration.ConfigColorEditor";
	}

	public sealed class KnownDrawerCommands
	{
		private KnownDrawerCommands() {}

		public const string ConfigurationCreate				= "ObjectiveDraw.Configuration.Create";
		public const string ConfigurationUpdate				= "ObjectiveDraw.Configuration.Update";
		public const string ConfigurationAccept				= "ObjectiveDraw.Configuration.Accept";
		public const string ConfigurationReject				= "ObjectiveDraw.Configuration.Reject";
		public const string ConfigurationExport				= "ObjectiveDraw.Configuration.Export";
		public const string ConfigurationImport				= "ObjectiveDraw.Configuration.Import";
		public const string NewDatabase						= "ObjectiveDraw.NewDatabase";
		public const string NewWorksheet					= "ObjectiveDraw.NewWorksheet";
		public const string CloseDatabase					= "ObjectiveDraw.CloseDatabase";
		public const string OpenDatabase					= "ObjectiveDraw.OpenDatabase";
		public const string SaveDatabase					= "ObjectiveDraw.SaveDatabase";
		public const string SaveAsDatabase					= "ObjectiveDraw.SaveAsDatabase";
		public const string PrevDatabase					= "ObjectiveDraw.PrevDatabase";
		public const string NextDatabase					= "ObjectiveDraw.NextDatabase";
		public const string DeleteAllShapes					= "ObjectiveDraw.DeleteAllShapes";
		public const string ToggleFullscreen				= "ObjectiveDraw.ToggleFullscreen";
		public const string DatabaseOptions					= "ObjectiveDraw.Database.Options";
		public const string ApplicationOptions				= "ObjectiveDraw.Application.Options";
	}

	public sealed class KnownDrawerResources
	{
		private KnownDrawerResources() {}
		[System.ComponentModel.Description("UIButtonCheckedLeaveBackImage")]
		public const string UIButtonCheckedLeaveBackImage	= "61A57158-98ED-4834-B847-D4455292B784";
		[System.ComponentModel.Description("UIButtonCheckedPressBackImage")]
		public const string UIButtonCheckedPressBackImage	= "03E3C365-79FE-4dca-868B-77A01729B4BA";
		[System.ComponentModel.Description("UIButtonCheckedEnterBackImage")]
		public const string UIButtonCheckedEnterBackImage	= "A7ED6238-2B0B-48bf-96D8-8739BA3B55DD";
		[System.ComponentModel.Description("UIButtonCheckedDisableBackImage")]
		public const string UIButtonCheckedDisableBackImage	= "0D82BE3A-4E53-4797-B64C-BB6779397E1A";
		[System.ComponentModel.Description("UIButtonNormalEnterBackImage")]
		public const string UIButtonNormalEnterBackImage	= "402537A0-BD59-4d17-ABC3-2EDC53841EE3";
		[System.ComponentModel.Description("UIButtonNormalPressBackImage")]
		public const string UIButtonNormalPressBackImage	= "FA72520E-4F26-438f-A44A-92741CEF14AA";
		[System.ComponentModel.Description("UIButtonNormalLeaveBackImage")]
		public const string UIButtonNormalLeaveBackImage	= "4EA2957B-167B-43c3-A188-EA31DED8C543";
		[System.ComponentModel.Description("UIButtonNormalDisableBackImage")]
		public const string UIButtonNormalDisableBackImage	= "E99557C9-6A2E-45f8-ABA4-20A620DC789B";
		[System.ComponentModel.Description("UICreateNewChartImage")]
		public const string UICreateNewChartImage			= "98B2A334-43DC-482d-91F7-3189776344A9";
	}

	public sealed class KnownDrawerVariables
	{
		private KnownDrawerVariables() {}
		// Format Window
		[System.ComponentModel.Browsable(false)]
		public const string DrawerComponentTypeName			= "DrawerComponentTypeName";

		[System.ComponentModel.Description("GraphBackgroundColor")]
		public const string GraphBackgroundColor			= "854DDD0E-BF2E-4bcc-9D7E-B57AA061A582";
		[System.ComponentModel.Description("ChartBackgroundColor")]
		public const string ChartBackgroundColor			= "F4E72539-F33B-4A59-B994-D4D681809D20";
		[System.ComponentModel.Description("GraphBackgroundImage")]
		public const string GraphBackgroundImage			= "3E6EFD27-AAFE-42f2-A37F-088185FB7035";

		[System.ComponentModel.Description("ChartHorizontalStrideColor")]
		public const string ChartHorizontalStrideColor		= "FD47759E-1B78-4123-BB4F-F3165AB75C19";
		[System.ComponentModel.Description("ChartHorizontalDatumColor")]
		public const string ChartHorizontalDatumColor		= "06F5C49D-DC24-4338-A965-CFD9AB87E818";

		[System.ComponentModel.Description("ChartOrdinateTenColor")]
		public const string ChartOrdinateTenColor			= "575AEFBD-B657-4E16-95D3-3ACA298908B4";
		[System.ComponentModel.Description("ChartOrdinateFiveColor")]
		public const string ChartOrdinateFiveColor			= "FFC3C28B-0083-4901-9C05-1B6E855A633C";
		[System.ComponentModel.Description("ChartOrdinateOneColor")]
		public const string ChartOrdinateOneColor			= "42069E52-2C66-4303-9E8C-D9F970A49265";
		
		[System.ComponentModel.Description("RulerHorizontalStrideColor")]
		public const string RulerHorizontalStrideColor		= "D184AD8E-5CBE-4508-ABDD-D31756E26C0E";
		//public const string RulerHorizontalHalfColor		= "2417EAD5-82F2-4787-88A3-A1CEF01AD8BF";
		[System.ComponentModel.Description("RulerHorizontalDatumColor")]
		public const string RulerHorizontalDatumColor		= "2F3639C5-B8EA-4bb1-A71B-4C90E6C8D6A6";
		[System.ComponentModel.Description("RulerHorizontalTextColor")]
		public const string RulerHorizontalTextColor		= "7059C2EA-159B-48a9-BBA3-43AF06B64C11";
		[System.ComponentModel.Description("RulerHorizontalBackColor")]
		public const string RulerHorizontalBackColor		= "D384560C-7D8B-49dc-B15F-F877531DCD8E";
		[System.ComponentModel.Description("RulerHorizontalBorderColor")]
		public const string RulerHorizontalBorderColor		= "BB9D479F-4881-483d-80C6-7918C3C6DE08";
		[System.ComponentModel.Description("RulerHorizontalBorderInteger")]
		public const string RulerHorizontalBorderInteger	= "20E981BA-6A00-4a86-A827-EA8AEBF4E579";

		[System.ComponentModel.Description("RulerOrdinateTenColor")]
		public const string RulerOrdinateTenColor			= "1535CBF9-3FBE-495d-A17D-9DCC13F7C33B";
		[System.ComponentModel.Description("RulerOrdinateFiveColor")]
		public const string RulerOrdinateFiveColor			= "316B3D06-FB07-49ba-B939-ABA7813BFF9F";
		[System.ComponentModel.Description("RulerOrdinateOneColor")]
		public const string RulerOrdinateOneColor			= "70BE4E7A-49A4-4713-A6E8-B2D759A705C7";
		[System.ComponentModel.Description("RulerOrdinateTextColor")]
		public const string RulerOrdinateTextColor			= "580EFDF8-3B22-4c85-9B15-6876530C1328";
		[System.ComponentModel.Description("RulerOrdinateBackColor")]
		public const string RulerOrdinateBackColor			= "B4274FDD-B5CE-47f9-AB1F-931FFB584A65";
		[System.ComponentModel.Description("RulerOrdinateBorderInteger")]
		public const string RulerOrdinateBorderInteger		= "5602EF30-EFCD-46c4-AA53-D6EA3A978862";
		[System.ComponentModel.Description("RulerOrdinateBorderColor")]
		public const string RulerOrdinateBorderColor		= "9A4B8F3C-10D3-432a-B031-1E7F51638BD4";


		[System.ComponentModel.Description("SplitterBackgroundColor")]
		public const string SplitterBackgroundColor			= "A1D36AAD-53BD-49e0-B41E-D5C4B4BE837B";		//
		[System.ComponentModel.Description("SplitterThicknessInteger")]
		public const string SplitterThicknessInteger		= "8B94AF3C-9990-4637-A5B3-87B6DE4AA521";		//

		[System.ComponentModel.Description("ShapeForegroundColor")]
		public const string ShapeForegroundColor			= "A6CC64F7-B148-45da-BC93-E4058019F54A";		//
		[System.ComponentModel.Description("ShapeManipulatorColor")]
		public const string ShapeManipulatorColor			= "0E0AC096-531D-43c6-87E5-09ACF4C6C5CF";		//
		[System.ComponentModel.Description("ShapeControlPrimaryColor")]
		public const string ShapeControlPrimaryColor		= "C1352168-20DA-489a-8934-E031B698127A";		//
		[System.ComponentModel.Description("ShapeControlServiceColor")]
		public const string ShapeControlServiceColor		= "CEBD45FF-6924-40d4-BEA5-5709F70FD126";		//
		[System.ComponentModel.Browsable(false)]
		public const string ShapeControlPointDateTime		= "E588B108-A128-4176-ABF9-0C5C695A769D";		//
		[System.ComponentModel.Browsable(false)]
		public const string ShapeControlPointOrdinate			= "8D6137D0-E568-41ed-A76B-BDB1EEBE9605";		//
		//public const string ShapeControlPointOrdinal		= "9046A7CB-A32C-4593-85C2-D3FAC046F3AB";		//
		//public const string ComplexObjectDrawerMousePoints	= "15CC561F-E044-46d2-9197-D1B4E3AAEC5C";		//
		//public const string ShapeControlPointCount			= "B9B3F16B-5E0D-4b68-88DD-6458F338B53C";		//
		[System.ComponentModel.Browsable(false)]
		public const string ShapeResourceCursor				= "1655594D-336F-4a05-A0A7-5BFA98455C67";		//
		
		//Illumination button
		//public const string ToolBarButtonLeaveFillColor		= "E26C3170-1B81-4B43-9E0E-92C68073711E";//
		[System.ComponentModel.Description("ToolBarButtonEnterFillColor")]
		public const string ToolBarButtonEnterFillColor		= "2B94051C-7DF3-490B-9917-00F4820764BA";//
		[System.ComponentModel.Description("ToolBarButtonCheckFillColor")]
		public const string ToolBarButtonCheckFillColor		= "A99CACA3-A176-4AD4-9D8B-F32F1365C281";//
		[System.ComponentModel.Description("ToolBarButtonPressFillColor")]
		public const string ToolBarButtonPressFillColor		= "D642D4CE-C338-424B-8970-001D1BF5DC20";//
		//public const string ToolBarButtonLeaveRectColor		= "4B91B4A9-CEE3-4D6D-AA05-27CAAB34FBA0";//
		[System.ComponentModel.Description("ToolBarButtonEnterRectColor")]
		public const string ToolBarButtonEnterRectColor		= "37480D01-FBD9-42C9-BED6-D3C6F35F47F8";//
		[System.ComponentModel.Description("ToolBarButtonCheckRectColor")]
		public const string ToolBarButtonCheckRectColor		= "970D657D-6A75-4C33-8040-A399801E01A3";//
		[System.ComponentModel.Description("ToolBarButtonPressRectColor")]
		public const string ToolBarButtonPressRectColor		= "A8DD6547-CB73-472F-9326-422489BFCBB5";//
		[System.ComponentModel.Description("ToolbarSeparatorBorderColor")]
		public const string ToolbarSeparatorBorderColor		= "1CE033CB-218D-4d9f-96BC-CDD5F59E3D3E";

		[System.ComponentModel.Description("ToolTipMessageFillColor")]
		public const string ToolTipMessageFillColor			= "1B2A8C86-F69F-4abd-A502-E1DDF59BAA51";//
		[System.ComponentModel.Description("ToolTipMessageRectColor")]
		public const string ToolTipMessageRectColor			= "BDFF5954-6270-4a49-97E6-182FF4254377";//
		[System.ComponentModel.Description("ToolTipMessageForeColor")]
		public const string ToolTipMessageForeColor			= "99E002B9-A427-47b8-90D3-12BF437DDA30";//
		[System.ComponentModel.Description("PanelTabButtonFontColor")]
		public const string PanelTabButtonFontColor			= "83A85564-F2F4-4307-844D-E4F095A7DEA2";//

		[System.ComponentModel.Browsable(false)]
		public const string ComplexObjectDrawerWindow		= "CAD8065F-17B4-4505-BB29-C87020424CF5";//
		[System.ComponentModel.Browsable(false)]
		public const string ComplexObjectDrawerCharts		= "F839AABC-3555-443f-A360-389E0AC554D4";//
		[System.ComponentModel.Browsable(false)]
		public const string ComplexObjectDrawerShapes		= "CADAF13E-A3F8-4dad-9BF0-69DE7719AC19";//

		[System.ComponentModel.Browsable(false)]
		public const string CoordinatePositionValueDateTime	= "F052080D-EF3C-4720-9D6B-5319870808F0";
		[System.ComponentModel.Browsable(false)]
		public const string CoordinatePositionScaleDouble		= "94318119-AD3B-422e-B33F-5A3CDCDF2B41";
		[System.ComponentModel.Browsable(false)]
		public const string CoordinatePositionMarginFloat		= "1FA10AF2-EF49-4ae6-B0FB-9D06F461A1B5";
		[System.ComponentModel.Browsable(false)]
		public const string CoordinatePositionOffsetFloat		= "94184014-3D4C-4c32-9ED3-34C5E9DF62DD";
		[System.ComponentModel.Browsable(false)]
		public const string CoordinatePositionApertureFloat	= "81B617B3-D506-4f42-BC30-8CDD21EB5948";		

		[System.ComponentModel.Browsable(false)]
		public const string GraphTimeShowLastTimeBoolean	= "3BE57898-E4F2-46a0-9FD0-1A5970C6564D";		

		/*
		public const string DisplayedValuesColor = "DisplayedValuesColor";
		//		public const string DirectionalValuesPosColor = "DirectionalValuesPosColor";//Positiv
		//		public const string DirectionalValuesNegColor = "DirectionalValuesNegColor";//Negativ
		//		public const string DirectionalValuesUnchColor = "DirectionalValuesUnchColor";//Unch
		public const string TimeAxisLabelsColor = "TimeAxisLabelsColor";//
		public const string OrdinateAxisLabelsColor = "OrdinateAxisLabelsColor";//
		public const string AxisLinesColor = "AxisLinesColor";//
		public const string SubGraphDividersColor = "SubGraphDividersColor";//color polosi megdu osnovnim grafikom i sub
		public const string SessionBreaksColor = "SessionBreaksColor";//break polosa chto schitaetsa po dnjam
		public const string PercentChangeBaseLineColor = "PercentChangeBaseLineColor";//percent shkala
		//highlight bar
		public const string BackgroundBarColor = "HighLightBarColor";//
		public const string ForegroundColor = "ForegroundColorColor";//text color
*/

	}

	/*public interface IDrawerProperty
	{
		string Name {get;}
		object Value {get;set;}
		//bool Changed {get;set;}
		//Instance
		//Dynamic
		//Database
	}*/

	public class SerializationGraphEntry
	{
		public object Instance;
		public bool Serialized;
		public SerializationGraphEntry(object instance, bool serialized)
		{
			this.Instance = instance;
			this.Serialized = serialized;
		}
	}

	public class SerializationContext
	{
		public SerializationContext(IDrawerComponent ownerComponent, Cerebrum.SerializeDirection direction, System.Collections.Hashtable objectsGraph)
		{
			this.Direction = direction;
			this.ObjectsGraph = objectsGraph;
			this.OwnerComponent = ownerComponent;
		}
		public System.Collections.Hashtable ObjectsGraph;
		public Cerebrum.SerializeDirection Direction;
		public IDrawerComponent OwnerComponent;

		public virtual SerializationContext CreateContext(IDrawerComponent ownerComponent)
		{
			return new SerializationContext(ownerComponent, this.Direction, this.ObjectsGraph);
		}

		public void AddInstance(ObjectiveDraw.Platform.IDrawerComponent instance, bool serialized)
		{
			if(instance.ObjectHandle != Cerebrum.ObjectHandle.Null)
			{
				this.ObjectsGraph[instance.ObjectHandle] = new SerializationGraphEntry(instance, serialized);
			}
		}
	}

}
